package com.lifeservice.console.controller;

import com.lifeservice.common.annotation.Log;
import com.lifeservice.common.core.controller.BaseController;
import com.lifeservice.common.core.domain.AjaxResult;
import com.lifeservice.common.core.page.TableDataInfo;
import com.lifeservice.common.enums.BusinessType;
import com.lifeservice.common.utils.SnowFlakeUtil;
import com.lifeservice.common.utils.poi.ExcelUtil;
import com.lifeservice.console.domain.LifeWxuser;
import com.lifeservice.console.service.ILifeWxuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 微信用户Controller
 *
 * @author lifeservice
 * @date 2023-02-27
 */
@RestController
@RequestMapping("/console/wxuser")
public class LifeWxuserController extends BaseController {
    @Autowired
    private ILifeWxuserService lifeWxuserService;

    /**
     * 查询微信用户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LifeWxuser lifeWxuser) {
        startPage();
        List<LifeWxuser> list = lifeWxuserService.selectLifeWxuserList(lifeWxuser);
        return getDataTable(list);
    }

    /**
     * 导出微信用户列表
     */
    @Log(title = "微信用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LifeWxuser lifeWxuser) {
        List<LifeWxuser> list = lifeWxuserService.selectLifeWxuserList(lifeWxuser);
        ExcelUtil<LifeWxuser> util = new ExcelUtil<LifeWxuser>(LifeWxuser.class);
        util.exportExcel(response, list, "微信用户数据");
    }

    /**
     * 获取微信用户详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(lifeWxuserService.selectLifeWxuserById(id));
    }

    /**
     * 新增微信用户
     */
    @Log(title = "微信用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LifeWxuser lifeWxuser) {
        lifeWxuser.setId(SnowFlakeUtil.getInstance().nextId());
        return toAjax(lifeWxuserService.insertLifeWxuser(lifeWxuser));
    }

    /**
     * 修改微信用户
     */
    @Log(title = "微信用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LifeWxuser lifeWxuser) {
        return toAjax(lifeWxuserService.updateLifeWxuser(lifeWxuser));
    }

    /**
     * 删除微信用户
     */
    @Log(title = "微信用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(lifeWxuserService.deleteLifeWxuserByIds(ids));
    }
}
